/*
 * DBManager.java
 *
 * Created on 4. juni 2007, 16:24
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package sja.util.db;

import javax.sql.RowSet;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author sevi
 */
public interface DBManager {

    /// <summary>
    /// Fetches a connection for the database. It has autocommit off, and you'll need to close it yourself
    /// </summary>
    /// <returns>A connection to the db. You may need to cast it to the correct dbtype at some point</returns>
    public Connection getConnection() throws SQLException;

    public void returnConnection();

    /// <summary>
    /// Executes a select statement that returns a number of rows
    /// </summary>
    /// <param name="sql">sql select statement</param>
    /// <returns>a filled DataTable</returns>
    public RowSet query(String sql);


    /**
     * Executes an update/insert/delete statement
     *
     * @param sql sql statement
     * @return the number of rows affected
     */
    public int execute(String sql);


    /// <summary>
    /// Execute a query and returns the first result of the first row. It uses OracleCommand.executeScalar
    /// </summary>
    /// <param name="sql">sql query</param>
    /// <returns>and object that can be cast to the correct datatype. If no rows are found OR the chosen field is null, then null is returned</returns>
    public Object queryForObject(String sql);
}
